layui.define(['table', 'form', 'admin', 'upload'], function (exports) {
    var $ = layui.$
        , table = layui.table
        , form = layui.form
        , upload = layui.upload
        , admin = layui.admin;

    //
    table.render({
        elem: '#LAY-guild-manager'
        , url: config.manager_get_list
        , cols: [[
            {field: 'id', width: 100, title: 'ID', sort: true}
            , {field: 'mobile', minWidth: 200, title: '手机号'}
            , {field: 'real_name', width: 200, title: '真实姓名'}
            , {
                field: '', width: 200, title: '直属上级', templet: function (d) {
                    return d.parent ? d.parent.real_name : '';
                }
            }
            , {
                field: '', width: 120, title: '角色', templet: function (d) {
                    return d.role ? d.role.name : '';
                }
            }
            , {
                field: '', width: 100, title: '分成比例', templet: function (d) {
                    if (d.role_id > 2) {
                        return d.sharing_ratio + "%";
                    }
                    return '';
                }
            }
            , {
                field: '', width: 80, title: '状态', templet: function (d) {
                    return d.status == 1 ? '<span class="layui-badge layui-bg-green">正常</span>' : '<span class="layui-badge layui-bg-orange">封禁</span>';
                }
            }
            , {field: 'create_time', width: 180, title: '创建日期'}
            , {title: '操作', width: 200, align: 'center', fixed: 'right', toolbar: '#table-guild-manager-operate'}
        ]]
        , page: true
        , limit: 20
        , height: 'full-180'
        , text: '对不起，加载出现异常！'
        , even: true
    });

    //监听工具条
    table.on('tool(LAY-guild-manager)', function (obj) {
        if (obj.event === 'edit') {
            var index = layer.open({
                type: 2
                , title: '编辑成员'
                , content: config.manager_edit + '?id=' + obj.data.id
                , maxmin: true
                , area: ['550px', '385px']
            });
        }

    });

    exports('guild/manager', {})
});